using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

namespace ProductExpirationAssistant
{
    public class ToggleGroupData : MonoBehaviour
    {
        public List<ToggleData> items = new List<ToggleData>();
        public FunctionType curType { get; private set; }
        public UnityEvent<FunctionType> onStateChanged = new UnityEvent<FunctionType>();

        private void Awake()
        {
            foreach (var item in items)
            {
                item.onStateChanged.AddListener(OnStateChanged);
            }
        }

        private void OnStateChanged(ToggleData item)
        {
            if (item.isOn && item.type != curType)
            {
                curType = item.type;
                onStateChanged.Invoke(curType);
            }
        }
    }
}